/*
 * OpenSCAD File with the code to draw a part of the quadcopter in 3D
 * Part Number: 13
 * Version: 0.01
 * Units: mm
 * Last Modification: Sun Jul 11 16:17:38 WEST 2010
 *
 * Copyright (C) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

frominclude = 0;

p13_sizewidth = 31;

module p13_pipesin()
{
	for (pos = [[12, 12, (4.5/2)-1.5],[-12, 12, (4.5/2)-1.5],
				[12, -12, (4.5/2)-1.5],[-12, -12, (4.5/2)-1.5]]) {
		translate(v = pos) {
			cylinder(h=4.5, r=1.5, center=true, $fn=60);
		}
	}
}

module p13_pipesout()
{
	for (pos = [[12, 12, (4/2)-1],[-12, 12, (4/2)-1],
				[12, -12, (4/2)-1],[-12, -12, (4/2)-1]]) {
		translate(v = pos) {
			cylinder(h=4, r=3.5, center=true, $fn=60);
		}
	}
}

module p13_holesinabutment()
{
	rotate(a=[90,0,0]) {
		translate(v = [(p13_sizewidth/2)-1-1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
		translate(v = [-(p13_sizewidth/2)+1+1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
	}
}

module p13_sidesupportsholes()
{
	for (a = [45, -45]) {
		for (p = [0, 13.37-2]) {
			rotate(a=[0,90,a]) {
				translate(v = [-(1.685+1+2+p), 27.74/2-1.685-2, 0]) {
					cylinder(h=3, r=1.685, center=true, $fn=60);
				}
				translate(v = [-(1.685+1+2+p), -(27.74/2-1.685-2), 0]) {
					cylinder(h=3, r=1.685, center=true, $fn=60);
				}
			}
		}
	}
}

module p13_sidesupports()
{
	translate(v = [0, 0, (18+5-(2+1.25))/2]) {
		rotate(a=[0, 0, 45]) {
			cube(size = [2, 26.94+0.8, 18+5-(2+1.25)], center=true);
		}
		rotate(a=[0, 0, -45]) {
			cube(size = [2, 26.94+0.8, 18+5-(2+1.25)], center=true);
		}
	}
}

module p13_horizontalsupports()
{
	translate(v = [0, 0, (6/2)-1]) {
		cube(size = [31, 2, 6], center=true);
	}
}

module p13_subcomponent()
{
	rotate(a=[90,0,0]) {
		translate(v = [0, (4/2)-1, 0]) {
			cylinder(h=32, r=2, center=true, $fn=60);
		}
	}
	p13_pipesin();
	p13_holesinabutment();
	translate(v = [0, 0, 18/2+3+2]) {
		cylinder(h=18, r=2, center=true, $fn=60);
	}
	translate(v = [0, 0, -2]) {
		cube(size = [p13_sizewidth+1, p13_sizewidth+1, 2], center=true);
	}
	translate(v = [0, 0, -1]) {
		cube(size = [2, p13_sizewidth+2, 2], center=true);
	}
	rotate(a=[0,90,0]) {
		translate(v = [-(18+5-1.25-2), 1.25+4.5, 0]) {
			cylinder(h=3, r=1.25, center=true, $fn=60);
		}
	}
	p13_sidesupportsholes();
}

module p13_addcomponent()
{
	cube(size = [p13_sizewidth, p13_sizewidth, 2], center=true);
	rotate(a=[90,0,0]) {
		translate(v = [0, (8/2)-3, 0]) {
			cylinder(h=p13_sizewidth, r=4, center=true, $fn=60);
		}
	}
	p13_pipesout();
	p13_sidesupports();
	translate(v = [0, 0, (18+5-6.5)/2]) {
		cylinder(h=18+5-6.5, r=6.5, center=true, $fn=60);
	}
	translate(v = [0, 0, (18+5)/2]) {
		cylinder(h=18+5, r=4.5, center=true, $fn=60);
	}
	p13_horizontalsupports();

	rotate(a=[0,90,0]) {
		translate(v = [-(18+5-3.25), 1.25+4.5, 0]) {
			cylinder(h=2, r=3.25, center=true, $fn=60);
		}
	}
	translate(v = [0, (1.25+3)/2+1.5, 6.5/2+18+5-6.5]) {
		cube(size = [2, 1.25+3, 6.5], center=true);
	}
}

module part13()
{
	difference() {
		union() {
			p13_addcomponent();
		}
		p13_subcomponent();
	}
}

if(frominclude == 0) {
	part13();
}